package com.example.controller;

import com.example.exception.BusinessException;
import com.example.pojo.Result;
import com.example.pojo.WxLoginQueryParam;
import com.example.service.LoginService;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 登录功能前端控制器
 */
@Controller
public class LoginController {

    @Resource
    private LoginService loginService;

    @RequestMapping("/login")
    @ResponseBody
    public Result login(@RequestBody WxLoginQueryParam queryParam){
        //交验参数
        if (StringUtils.isEmpty(queryParam.getCode())){
            throw new BusinessException(500,"登录失败不能为空");
        }
        //调用业务层逻辑返回结果
        return loginService.login(queryParam.getCode());
    }

    @GetMapping("/credit")
    @ResponseBody
    public Result getUserCredit(String token){
//调用业务层逻辑返回结果
        return loginService.getUserCredit(token);
    }
}
